package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.utils.PageUtils;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.manager.mapper.CategoryBrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author Windows
 * @description 针对表【category_brand(分类品牌)】的数据库操作Service实现
 * @createDate 2024-01-31 15:58:24
 */
@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand>
        implements CategoryBrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Override
    public Page<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto categoryBrandDto) {

        List<CategoryBrand> categoryBrandList = this.baseMapper.findByPage(categoryBrandDto);
        Page<CategoryBrand> categoryBrandPage = PageUtils.listToPage(categoryBrandList, page, limit);

        return categoryBrandPage;
    }

    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        List<CategoryBrand> list = this.list(new LambdaQueryWrapper<CategoryBrand>()
                .eq(CategoryBrand::getCategoryId, categoryId));
        List<Long> brandIdList = list.stream().map(CategoryBrand::getBrandId).collect(Collectors.toList());


        List<Brand> brandList = brandMapper.selectBatchIds(brandIdList);
        return brandList;
    }
}




